﻿
<div class="modal fade" id="myModal_EditGords" tabindex="-100" role="dialog" data-backdrop="static" aria-labelledby="myModalEditGoos" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h5 class="modal-title"><span class="glyphicon glyphicon-pencil text-danger"></span>&nbsp;&nbsp;<span class="label label-danger">@ViewData["GoodsSortName"] </span>&nbsp;大类</h5>
            </div>
            <div class="modal-body">
                <form action="#">
                    <input type="hidden" name="GoodsID" />
                    <div class="form-group">
                        <label for="GoodsName">商品名称:</label>
                        <input type="text" class="form-control" name="GoodsName" placeholder="商品名称" value={{}}}>
                    </div>
                    <div class="form-group">
                        <label for="SalePrice">销售单价:</label>
                        <input type="text" name="SalePrice" class="form-control" placeholder="销售单价" value={{}}>
                    </div>
                    <div class="form-group">
                        <label for="Quntity">货架数量:</label>
                        <input type="text" name="Quntity" class="form-control" placeholder="货架数量" value={{}}>
                    </div>
                    <div class="form-group">
                        <label for="PurchasePrice">进价:</label>
                        <input type="text" name="PurchasePrice" class="form-control" placeholder="商品进价" value={{}}>
                    </div>
                    <div class="form-group">
                        <label for="MeasureUnite">单位换算关系:</label>

                        <div class="row">
                            <div class="col-md-3 col-xs-3 col-sm-3 "><input type="text" name="MeasureUnite" class="form-control" placeholder="货架度量" value={{}}></div>

                            <div class="col-md-1"><span class="glyphicon glyphicon-remove"></span></div>
                            <div class="col-md-3 col-xs-3 col-sm-3">
                                <input type="text" name="Multiple" class="form-control" placeholder="乘积" value={{}}>
                            </div>
                            <div class="col-md-2"><span class="glyphicon glyphicon-arrow-right"></span></div>

                            <div class="col-md-3 col-xs-3 col-sm-3"><input type="text" name="StockUnite" class="form-control" placeholder="库存度量" value={{}}></div>
                        </div>

                    </div>

                    <div class="form-group">
                        <label for="StockQuntity">库存数量:</label>
                        <input type="text" name="StockQuntity" class="form-control" placeholder="库存数量" value={{}}>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <span class="text-danger">输入商品分类不能为空</span>
                <button type="button" class="btn btn-danger">表单样式复原</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="btn_EditGords_">提交</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //模态框关闭之后触发
    $("#myModal_EditGords").on('hidden.bs.modal', function (e) {

        // $(this).removeData("bs.modal");
        $('#myModal_EditGords form').data('bootstrapValidator').resetForm(true);
        $("#Pannel_Goodslist").load('Admin/GoodssByTeamID/' + '@ViewData["GoodsSortID"]');
    });
    $('#myModal_EditGords').on('show.bs.modal', function (e) {

        $("#myModal_EditGords .modal-footer>span").html("");
    })

    $('#myModal_EditGords .modal-footer>.btn:first').click(function () {

        $('#myModal_EditGords form').data('bootstrapValidator').resetForm(true);
    });
    //提交的ajax
    $("#myModal_EditGords form").submit(function (ev) { ev.preventDefault(); });
    $("#btn_EditGords_").on("click", function () {

        var bootstrapValidator = $('#myModal_EditGords form').data('bootstrapValidator');
        bootstrapValidator.validate();
        if (bootstrapValidator.isValid()) {
            $.ajax({
                type: 'POST',
                data: "GoodsName=" + $("#myModal_EditGords").find("input[name='GoodsName']").val()
                    + "&Quntity=" + $("#myModal_EditGords").find("input[name='Quntity']").val()
                    + "&SalePrice=" + $("#myModal_EditGords").find("input[name='SalePrice']").val()
                     + "&PurchasePrice=" + $("#myModal_EditGords").find("input[name='PurchasePrice']").val()
                     + "&MeasureUnite=" + $("#myModal_EditGords").find("input[name='MeasureUnite']").val()
                    + "&Multiple=" + $("#myModal_EditGords").find("input[name='Multiple']").val()
                    + "&StockUnite=" + $("#myModal_EditGords").find("input[name='StockUnite']").val()
                    + "&GoodsID=" + $("#myModal_EditGords").find("input[name='GoodsID']").val(),
                url: 'Admin/btn_EditGoods',
                success: function (data) {

                    if (data == "ok") {
                        //$("#myModal_AddGords").modal("hide");
                        //刷新下拉菜单绑定的商品分类

                        //增加添加成功信息

                        $("#myModal_EditGords .modal-footer").find("span").show().html("修改成功！");
                    }
                    else { alert("没有成功"); }

                },
                error: function (error) {
                    alert(error.responseText);
                }
            });
        }
        else return;

    });

</script>
<script type="text/javascript">

    $(function () {
        $('#myModal_EditGords form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                GoodsName: {
                    message: '用户名验证失败',
                    validators: {
                        notEmpty: {
                            message: '商品名不能为空！'
                        }
                    }
                },
                Quntity: {
                    validators: {
                        integer: {
                            //creditCardField: 'Quntity',
                            message: '必须输入整数'
                        }
                    }
                },
                SalePrice: {
                    validators: {
                        numeric: {
                            message: '价格必须是数字'
                        }
                    }
                },
                PurchasePrice: {
                    validators: {
                        numeric: {
                            message: '价格必须是数字'
                        }
                    }
                },
                StockQuntity: {
                    validators: {
                        integer: {
                            message: '必须是整数'
                        }
                    }
                },
                Multiple: {
                    validators: {
                        integer: {
                            message: '必须是整数'
                        }
                    }
                }
            }
        });
    });
</script>